History vs. HistorySession, Is ID Numbering Offset by 1?

Suppose you are working on a module. I was thinking if you found the max ID number from HistorySession and looked for history of interest in History matching said ID number, that would be the way to go. To my surprise I found nothing. This is because HistorySession starts with 0 and History starts with 1 ("can't we all get along?").

After some empirical observations, I saw that:
HistorySession numbering is 0 .. (N-1) with no gaps.
History.sessionNo numbering is 1 .. N with gaps if no history.

Seemingly, to bridge the two domains, we must add 1 from HistorySession to make a correspondence with History entries.

QUESTION: Is this true or is this an unreliable conclusion that just happens to be true in many cases?

See code below as an illustration:

int getHistoryNoForThisSession() {
    int historyNo = -1; // -1 means something wrong
    HistorySession historySession = (HistorySession null);
    for historySession in current Module do { /* notta */ }
    // is there as Last() function or similar?
    if (!null(historySession)) {
        //----------------------------------------------------------------------
        // Empirical obsevation: 
        //     HistorySession numbering is 0 .. (N-1) with no gaps
        //     History.sessionNo numbering is 1..N with gaps if no history
        // To bridge the two domains we must add 1 from HistorySession to
        // make a correspondence (???).
        //----------------------------------------------------------------------
        historyNo = number(historySession) + 1;   
    }
    return historyNo; 
}                                                                                                                                      
 
string getIntSkipListKeysAsCsvStr(Skip skip) {
    string retVal = "";
    if (null(skip)) {
        // nothing;
    } else {
        Buffer b = create();
        int element;
        for element in skip do {
            b += "" (int key skip) "";
            b += ", ";
        }
        retVal = stringOf(b[0:(length(b) - 3)]);
        delete(b);
    }
    return retVal;
}
 
void sessionNoDiscovery() {
    Skip numberSkip = create();
    Skip sessionNoSkip = create();
 
    HistorySession historySession = (HistorySession null);
    for historySession in current Module do {
        // Store unique numbers as set
        put(numberSkip, number(historySession), 0); // no data, just key
    }
    History history = (History null);
    for history in current Module do {
        // Store unique numbers as set
        put(sessionNoSkip, history.sessionNo, 0); // no data, just key
    }
    print("The History.historyNo for the current session is " (getHistoryNoForThisSession()) "\n\n");
 
    print("Unique number() on members in HistorySession gives: " getIntSkipListKeysAsCsvStr(numberSkip) "\n");
    print("Unique history.sessionNo on members in History gives: " getIntSkipListKeysAsCsvStr(sessionNoSkip) "\n");
    delete(numberSkip);
    delete(sessionNoSkip);
}                                                                                                                                      
// Call it here:
sessionNoDiscovery();

 


Output shows:
The History.historyNo for the current session is 156

Unique number() on members in HistorySession gives: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155

Unique history.sessionNo on members in History gives: -1, 1, 2, 7, 9, 11, 15, 16, 17, 18, 20, 21, 23, 27, 28, 29, 31, 32, 33, 36, 37, 40, 41, 42, 44, 48, 50, 51, 52, 53, 56, 57, 58, 59, 60, 61, 62, 67, 68, 77, 78, 80, 81, 102, 104, 110, 111, 134, 135, 136, 144, 146, 147, 156

 


SystemAdmin - Fri Jun 11 11:53:56 EDT 2010

Re: History vs. HistorySession, Is ID Numbering Offset by 1?
a_vestlin - Mon Jun 14 02:38:57 EDT 2010

I think it is true. I see the same thing.

In the history tab in Module Properties the session number seems be +1 compared to number(HistorySession).

/Anders

Re: History vs. HistorySession, Is ID Numbering Offset by 1?
llandale - Tue Jun 15 14:36:33 EDT 2010

I've got a HistoryReport.dxl script. The GUI and the DXL dumping history for the module agree on which Session is associated with which each History. Your numbers are off by one because you are adding one to the Sesssion Number in function getHistoryNoForThisSession(). Did I miss something? The following gets the current Session number, which is null when the module is open Read.

Module m = current()
HistorySession hsCurr = current(m)
if (null hsCurr) //
then print "Current Session is null\n"
else print "Current Session = " number(hsCurr) "\n"


I see that the Session Number is permanantly increased by 1 every time you open the module Shared. I thought I found a case where it didn't permamntly assign a session number for an Edited module that had no history and was then closed; but it seems the Session is permamantly updated. I see the 'current Session' is incorrectly preserved if you open Edit, then downgrade to Read.

I would like to point out that History in the module is not perfectly chronological; nor are the sessions. If two folks share the module at the same time, locking different sections and making changes, that History is preserved in the order in which the module is SAVED by each person, not by Session number nor by Date of the Change.

 

 

  • Louie

 

 

Re: History vs. HistorySession, Is ID Numbering Offset by 1?
llandale - Tue Jun 15 15:06:09 EDT 2010

llandale - Tue Jun 15 14:36:33 EDT 2010

I've got a HistoryReport.dxl script. The GUI and the DXL dumping history for the module agree on which Session is associated with which each History. Your numbers are off by one because you are adding one to the Sesssion Number in function getHistoryNoForThisSession(). Did I miss something? The following gets the current Session number, which is null when the module is open Read.

Module m = current()
HistorySession hsCurr = current(m)
if (null hsCurr) //
then print "Current Session is null\n"
else print "Current Session = " number(hsCurr) "\n"


I see that the Session Number is permanantly increased by 1 every time you open the module Shared. I thought I found a case where it didn't permamntly assign a session number for an Edited module that had no history and was then closed; but it seems the Session is permamantly updated. I see the 'current Session' is incorrectly preserved if you open Edit, then downgrade to Read.

I would like to point out that History in the module is not perfectly chronological; nor are the sessions. If two folks share the module at the same time, locking different sections and making changes, that History is preserved in the order in which the module is SAVED by each person, not by Session number nor by Date of the Change.

 

 

  • Louie

 

 

OK. I think I see what you are getting at, even though you didn't get at it clearly. Find a small module, edit it, make a change, save and close, then open the module Read. Run the following

HistorySession    hs
History         his
 
print "Session\tDate\t\tWho\t\tMode\t<<-- for Sessions\n"
for hs in (current Module) do
{  print number(hs) "\t" when(hs) "\t" who(hs) "\t" mode(hs) "\n"
}
 
print "Session\tDate\t\tAuthor\t\tHistoryType\t<-- for History\n"
for his in (current Module) do
{  print (his.sessionNo) "\t" (his.date) "\t"  (his.author) "\t" (goodStringOf(his.type) )"\n"
}
For me, prints this:
Session Date                    Who             Mode    <<-- for Sessions
0       06/15/10 13:38:27       landalo-Admin   0
1       06/15/10 13:41:26       landalo-Admin   0
2       06/15/10 13:43:41       landalo-Admin   0
3       06/15/10 13:56:45       landalo-Admin   2
4       06/15/10 13:56:52       landalo-Admin   0
5       06/15/10 13:56:59       landalo-Admin   2
Session Date                    Author          HistoryType     <-- for History
1       06/15/10 13:38:27       landalo-Admin   Create Module
1       06/15/10 13:39:33       landalo-Admin   Create Object
3       06/15/10 13:48:14       landalo-Admin   Modify Object
6       06/15/10 13:57:11       landalo-Admin   Modify Object


Looking at the time of the History I see that the Session number referenced in the History (last one is #6 at 13:57:11) corresponds to the list of Session Numbers minus 1 (last session was #5 starting at 13:56:59).

So yes, if you are comparing the Session of a History with the actual Sessions, subtract one. Or better yet, when ever dealing with the Session loop, always add one. Seems like a bug to me.

 

 

  • Louie


I see that 'edit' is mode 0 while 'shared' is mode 2.

 

 

Re: History vs. HistorySession, Is ID Numbering Offset by 1?
SystemAdmin - Tue Jun 15 16:48:28 EDT 2010

llandale - Tue Jun 15 15:06:09 EDT 2010

OK. I think I see what you are getting at, even though you didn't get at it clearly. Find a small module, edit it, make a change, save and close, then open the module Read. Run the following

HistorySession    hs
History         his
 
print "Session\tDate\t\tWho\t\tMode\t<<-- for Sessions\n"
for hs in (current Module) do
{  print number(hs) "\t" when(hs) "\t" who(hs) "\t" mode(hs) "\n"
}
 
print "Session\tDate\t\tAuthor\t\tHistoryType\t<-- for History\n"
for his in (current Module) do
{  print (his.sessionNo) "\t" (his.date) "\t"  (his.author) "\t" (goodStringOf(his.type) )"\n"
}
For me, prints this:
Session Date                    Who             Mode    <<-- for Sessions
0       06/15/10 13:38:27       landalo-Admin   0
1       06/15/10 13:41:26       landalo-Admin   0
2       06/15/10 13:43:41       landalo-Admin   0
3       06/15/10 13:56:45       landalo-Admin   2
4       06/15/10 13:56:52       landalo-Admin   0
5       06/15/10 13:56:59       landalo-Admin   2
Session Date                    Author          HistoryType     <-- for History
1       06/15/10 13:38:27       landalo-Admin   Create Module
1       06/15/10 13:39:33       landalo-Admin   Create Object
3       06/15/10 13:48:14       landalo-Admin   Modify Object
6       06/15/10 13:57:11       landalo-Admin   Modify Object


Looking at the time of the History I see that the Session number referenced in the History (last one is #6 at 13:57:11) corresponds to the list of Session Numbers minus 1 (last session was #5 starting at 13:56:59).

So yes, if you are comparing the Session of a History with the actual Sessions, subtract one. Or better yet, when ever dealing with the Session loop, always add one. Seems like a bug to me.

 

 

  • Louie


I see that 'edit' is mode 0 while 'shared' is mode 2.

 

 

Thanks for your response.

Before closing the issue I have a related question. Often there are several ways to solve a problem but sometimes one is easier or more reliable than the other.

Suppose:
1) A user opens a module in exclusive edit mode.
2) The desire is to:
--> a) Set an int variable (call it mySessionId) that with certainty corresponds to the session the user opened the module with.
--> b) Upon some arbitrary event (menu, button press, module close) gather some information from History that were associated with the current module edit session by this user.

I was thinking that I could:
--> a) set mySessionId to the max id from HistorySession
--> b) increment mySessionId by 1
--> c) probe History for items of interest with (history.sessionNo == mySessionId)

Is there a more reliable way to do this? Stated another way, what is the best way to discover the session ID you are currently "Exclusive Editing" under? Now I'm concerned about what happens if someone else opens the module read-only after I started the exclusive edit session. I'm scared of getting the wrong session ID.

Re: History vs. HistorySession, Is ID Numbering Offset by 1?
SystemAdmin - Tue Jun 15 17:46:20 EDT 2010

SystemAdmin - Tue Jun 15 16:48:28 EDT 2010
Thanks for your response.

Before closing the issue I have a related question. Often there are several ways to solve a problem but sometimes one is easier or more reliable than the other.

Suppose:
1) A user opens a module in exclusive edit mode.
2) The desire is to:
--> a) Set an int variable (call it mySessionId) that with certainty corresponds to the session the user opened the module with.
--> b) Upon some arbitrary event (menu, button press, module close) gather some information from History that were associated with the current module edit session by this user.

I was thinking that I could:
--> a) set mySessionId to the max id from HistorySession
--> b) increment mySessionId by 1
--> c) probe History for items of interest with (history.sessionNo == mySessionId)

Is there a more reliable way to do this? Stated another way, what is the best way to discover the session ID you are currently "Exclusive Editing" under? Now I'm concerned about what happens if someone else opens the module read-only after I started the exclusive edit session. I'm scared of getting the wrong session ID.

Louie, I did not know about the mode(HistorySession) because it is not documented in the DOORS help file (in V8.2 anyway)(not that this is a rare find).

To be more sure of identifying the current "Exclusive Edit" session, the query on HistorySession could filter for only sessions with "Exclusive Edit" mode as follows:
 

int getHistoryNoForThisExclusiveEditSession() {
    int historyNo = -1; // - means something wrong or none found
    int historySessionNo = -1; // - means something wrong or none found
    HistorySession historySession = (HistorySession null);
 
    for historySession in current Module do { 
        if (mode(historySession) == 0) { // exclusive edit
            historySessionNo = number(historySession);        
        }
    }
    // is there as Last() function or similar?
    if (historySessionNo > -1) {
        //----------------------------------------------------------------------
        // Empirical observation: 
        //     HistorySession numbering is 0 .. (N-1) with no gaps
        //     History.sessionNo numbering is 1..N with gaps if no history
        // To bridge the two domains we must add 1 from HistorySession to
        // make a correspondance.
        //----------------------------------------------------------------------
        historyNo = historySessionNo + 1;   
    }
    return historyNo; 
}


However further study reveals the additional qualification is not necessary because:

DOOR help file V8.2:

 "Every time a DOORS module is opened in either edit or shareable mode, a session summary is saved."
"You can access this information using the functions that act on an object of type HistorySession."


Since there is no HistorySession increment for read-only access, there is need to worry.



 

 

 

 

 

"Every time a DOORS module is opened in either edit or shareable mode, a session summary is saved."
"You can access this information using the functions that act on an object of type HistorySession."

Re: History vs. HistorySession, Is ID Numbering Offset by 1?
llandale - Tue Jun 15 19:41:53 EDT 2010

SystemAdmin - Tue Jun 15 16:48:28 EDT 2010
Thanks for your response.

Before closing the issue I have a related question. Often there are several ways to solve a problem but sometimes one is easier or more reliable than the other.

Suppose:
1) A user opens a module in exclusive edit mode.
2) The desire is to:
--> a) Set an int variable (call it mySessionId) that with certainty corresponds to the session the user opened the module with.
--> b) Upon some arbitrary event (menu, button press, module close) gather some information from History that were associated with the current module edit session by this user.

I was thinking that I could:
--> a) set mySessionId to the max id from HistorySession
--> b) increment mySessionId by 1
--> c) probe History for items of interest with (history.sessionNo == mySessionId)

Is there a more reliable way to do this? Stated another way, what is the best way to discover the session ID you are currently "Exclusive Editing" under? Now I'm concerned about what happens if someone else opens the module read-only after I started the exclusive edit session. I'm scared of getting the wrong session ID.

Using that current() command (from my first post) to get the current Session number has just got to be more reliable than presuming that the most recent session in the module is the current one. That is definately true for shared, as someone else could have opened shared after you did. If the module is open edit or shared it should be reliable; if its open read then set it to -1. And yes, you need to add one if you figure to look for History associated with the current Session.

Now let me guess. You are looking for unsaved edits in the current session, wondering if perhaps you should close without saving? Don't know how to do that. I see that the dateAndTime of the module's Last Modified On attribute is updated when you change, not udpated when you save. If you discard edits that value returns to its earlier value.

  • Louie

Re: History vs. HistorySession, Is ID Numbering Offset by 1?
SystemAdmin - Tue Jun 15 19:58:33 EDT 2010

llandale - Tue Jun 15 19:41:53 EDT 2010
Using that current() command (from my first post) to get the current Session number has just got to be more reliable than presuming that the most recent session in the module is the current one. That is definately true for shared, as someone else could have opened shared after you did. If the module is open edit or shared it should be reliable; if its open read then set it to -1. And yes, you need to add one if you figure to look for History associated with the current Session.

Now let me guess. You are looking for unsaved edits in the current session, wondering if perhaps you should close without saving? Don't know how to do that. I see that the dateAndTime of the module's Last Modified On attribute is updated when you change, not udpated when you save. If you discard edits that value returns to its earlier value.

  • Louie

Sorry, I focused on your second post and glanced over the first post. The number(hsCurr) from below seems fine.
 

Module m = current()
HistorySession hsCurr = current(m)
if (null hsCurr) //
then print "Current Session is null\n"
else print "Current Session = " number(hsCurr) "\n"

 


I'll get this value; increment it by one; and probe History per app desire.

Thanks -- closing issue
(others be aware of the HistorySession numbering 0 .. (N-1) and History.sessionNo numbering 1 .. N inconsistency.)